import formatCalendar from './calendar.js';
let calendar={
	getLunar(year,month,date){
		return formatCalendar.solar2lunar(year,month,date);
	},
	formatNum(n){
		return n<10?'0'+n:n+''
	},
	init(initDate){
		let _this=this;
		let aDate=new Date(initDate);
		let year=aDate.getFullYear();
		let month=aDate.getMonth();
		let date=aDate.getDate();
		let day=aDate.getDay();
		let data=[];
		let lastMonthDays=new Date(year, month, 0).getDate();
		let curMonthFirstDay=new Date(year, month, 1).getDay();
		let initDay=lastMonthDays-curMonthFirstDay+1;
		let curIndex=0;
		aDate.setMonth(month-1);
		aDate.setDate(initDay);
		for(let k=0;k<42;k++){
			data.push({
				isCurrentMonth:aDate.getMonth()==month?true:false,
				year:aDate.getFullYear(),
				month:_this.formatNum(aDate.getMonth()+1),
				date:_this.formatNum(aDate.getDate()),
				isToday:aDate.getMonth()==month&&aDate.getDate()==date?true:false,
				fullDate:aDate.getFullYear()+"-"+_this.formatNum(aDate.getMonth()+1)+"-"+_this.formatNum(aDate.getDate()),
				lunar:_this.getLunar(aDate.getFullYear(),_this.formatNum(aDate.getMonth()+1),_this.formatNum(aDate.getDate()))
			});
			aDate.setDate(aDate.getDate()+1)
		};
		data.map((v,k)=>{
			if(v.isToday)curIndex=k;
		})
		return{
			year,
			month:_this.formatNum(month+1),
			date:_this.formatNum(date),
			data,
			currentIndex:curIndex
		}
	}
}
export default calendar